package com.wzcl.app.model.vo;

import com.wzcl.app.dao.model.AppUser;
import com.wzcl.app.model.common.WZCL;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;

import java.math.BigDecimal;
import java.util.Map;


@EqualsAndHashCode(callSuper = false)
@Data
public class AppUserVo extends BaseVo {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(value = "用户在系统内的昵称")
    private String nickName;

    @ApiModelProperty(value = "用户真实姓名")
    private String realName;

    @ApiModelProperty(value = "性别")
    private Integer sex;
    private String sexStr;

    @ApiModelProperty(value = "用户手机号,userName")
    private String phone;

    @ApiModelProperty(value = "用户类型")
    private Integer type;
    private String typeStr;

    @ApiModelProperty(value = "是否删除")
    private Integer state;
    private String stateStr;

    @ApiModelProperty(value = "用户状态")
    private Integer userState;
    private String userStateStr;

    @ApiModelProperty(value = "头像的文件ID")
    private String headIcon;

    //-----相关的-------//
    @ApiModelProperty(value = "权限")
    private String userRole;

    @ApiModelProperty(value = "详情")
    private UserInfoVo userInfo;

    private Integer gradeId;
    private String gradeName;

    @ApiModelProperty(value = "当前积分")
    private String score;

    private AppUserVo() {
    }


    public static AppUserVo create(AppUser appUser){
        AppUserVo appUserVo = new AppUserVo();
        BeanUtils.copyProperties(appUser,appUserVo,"userInfo","score");
        appUserVo.setScore(appUser.getScore().setScale(2,BigDecimal.ROUND_DOWN).toString());
        if(appUser.getRoleList()!=null && appUser.getRoleList().size()>0){
            appUserVo.userRole = appUser.getRoleList().get(0).getName();
        }
        if(appUser.getUserInfo() != null){
            appUserVo.userInfo = UserInfoVo.create(appUser.getUserInfo());
        }
        if(appUser.getGrade()!=null){
            appUserVo.gradeId = appUser.getGrade().getId();
            appUserVo.gradeName = appUser.getGrade().getName();
        }
        if(StringUtils.isBlank(appUser.getHeadIcon())){
            appUserVo.headIcon = DEFAULT_AVATAR_IMAGE;
        }
        if(StringUtils.isBlank(appUser.getRealName())){
            appUserVo.realName = "";
        }
        appUserVo.translationValueStr();
        return appUserVo;
    }

    @Override
    public void translationValueStr() {
        Map<String, Map<Integer, String>> map = getTranslationMap();
        this.sexStr = this.sex == null?"未知":this.sex == 0?"男":"女";
        this.typeStr = map.get(WZCL.GROUP_NAME.USER_TYPE).get(this.type);
        this.stateStr = map.get(WZCL.GROUP_NAME.STATE).get(this.state);
        this.userStateStr = map.get(WZCL.GROUP_NAME.USER_STATE).get(this.userState);
    }

    @Override
    public void processResources() {

    }
}
